using System;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BookBarter;

/// <summary>
/// This class controls all of the notification process.  It instantiates all of the classes in the notification process.
/// </summary>
public class NotificationMain
{
    private EmailNotifier _email;
    private RssNotifier _rss;
    private WebUINotifier _web;

	public NotificationMain()
	{
		//
		// TODO: Add constructor logic here
		//

        _email = new EmailNotifier();
        _rss = new RssNotifier();
        _web = new WebUINotifier();



        PerformNotification(TradeRoute.GetAllTradeRoutesNotNotified());

        
	}
    /// <summary>
    /// Perform Notification on a trade route.
    /// </summary>
    /// <param name="tradeRoute">This is the trade route object</param>
    public void PerformNotification(List<TradeRoute> tradeRoutes)
    {
        //TODO:
        //Get book information for that trade
        //End TODO

        foreach (TradeRoute tr in tradeRoutes)
        {
            TradeLink tradeLink = tr.FirstLink;

            //ForEach want/have in the tradeRoute object
            while (tradeLink.NextTradeLink != null)
            {
                if (tradeLink.Notified == false)
                {
                    //we need to notifiy the person in this trade link

                    AcceptedStatus accepted = tradeLink.Accepted;
                    _email.Notify(tradeLink, accepted);
                    _rss.Notify(tradeLink, accepted);

                    

                    tradeLink.Notified = true;
                    //TODO: save the link to database (changed notified value)

                    //start the next node
                    tradeLink = tradeLink.NextTradeLink;
                }
            }

        }

    }
}
